package org.huawei260.TiKu.ODsuanfa;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Scanner;

/**
 * @Author: qingle
 * @Date: 2024/10/28-16:11
 * @Description: 3803 【回溯】2023B猜密码
 * @version: 1.0
 */
public class B_2023B_3803__回溯猜密码 {


//	public class Main {
		static int[] nums;
		static int level;

		public static void main(String[] args) {
			Scanner sc = new Scanner(System.in);

			nums = Arrays.stream(sc.nextLine().split(",")).mapToInt(Integer::parseInt).toArray();
			level = Integer.parseInt(sc.nextLine());

			System.out.println(getResult());
		}

		public static String getResult() {
			// 按照数值大小升序，这样后续形成的组合的内部就是按照数值大小升序的
			Arrays.sort(nums);

			// 求不重复组合
			ArrayList<String> res = new ArrayList<>();
			dfs(0, new LinkedList<>(), res);

			if (res.size() > 0) {
				// 组合间按照字典序排序
				res.sort(String::compareTo);
				return String.join("\n", res);
			} else {
				return "None";
			}
		}

		public static void dfs(int index, LinkedList<String> path, ArrayList<String> res) {
			if (path.size() >= level) {
				// 如果path层数到达level层，则记录该组合
				res.add(String.join(",", path));
			}

			for (int i = index; i < nums.length; i++) {
				// 树层去重
				if (i > 0 && nums[i] == nums[i - 1]) continue;

				path.add(nums[i] + "");
				dfs(i + 1, path, res);
				path.removeLast();
			}
		}
	}